/*
 * FQuestion.java
 *
 * Created on 02 March 2005, 19:58
 */

package org.foment.joliage3.newt;

/**
 *
 * @author  civan
 */
public class Message extends javax.swing.JDialog {
  public int status; 
  public static final int STATUS_YES        = 1;
  public static final int STATUS_NO         = 2;
  public static final int STATUS_UNDEFINED  = 0;
  /** Creates new form FQuestion */
  public Message(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    setAlwaysOnTop(true);
    initComponents();
    status = STATUS_UNDEFINED;
  }
  
  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
  private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    btn = new javax.swing.JButton();
    scroll = new javax.swing.JScrollPane();
    txtMessage = new javax.swing.JTextPane();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setBackground(new java.awt.Color(255, 255, 255));
    setResizable(false);
    jPanel1.setLayout(new java.awt.GridLayout(1, 0));

    btn.setText("OK");
    btn.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(java.awt.event.MouseEvent evt) {
        btnMouseClicked(evt);
      }
    });

    txtMessage.setEditable(false);
    scroll.setViewportView(txtMessage);

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(layout.createSequentialGroup()
        .add(551, 551, 551)
        .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 396, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      .add(layout.createSequentialGroup()
        .addContainerGap()
        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
          .add(org.jdesktop.layout.GroupLayout.LEADING, btn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .add(org.jdesktop.layout.GroupLayout.LEADING, scroll, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(layout.createSequentialGroup()
        .addContainerGap()
        .add(scroll, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
          .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
          .add(btn))
        .addContainerGap())
    );
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-429)/2, (screenSize.height-221)/2, 429, 221);
  }// </editor-fold>//GEN-END:initComponents

  private void btnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnMouseClicked
    status = STATUS_YES;
    this.setVisible(false);    
  }//GEN-LAST:event_btnMouseClicked
  
  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new Question(new javax.swing.JFrame(), true).setVisible(true);
      }
    });
  }
  
  public static int showMessage(String caption, String message, String buttonText) {
    Message fq = new Message(new javax.swing.JFrame(), true);
    fq.setTitle(caption);
    fq.txtMessage.setText(message);
    fq.btn.setText(buttonText);
    fq.scroll.getViewport().setViewPosition(new java.awt.Point(1, 1));
    fq.txtMessage.scrollRectToVisible(new java.awt.Rectangle(1, 1, 1, 1));
    fq.setVisible(true);
    return fq.status;
  }
  
  // Variables declaration - do not modify//GEN-BEGIN:variables
  public javax.swing.JButton btn;
  public javax.swing.JPanel jPanel1;
  public javax.swing.JScrollPane scroll;
  public javax.swing.JTextPane txtMessage;
  // End of variables declaration//GEN-END:variables
  
}
